/*
 * @file yt_extension
 * @Author: liuer
 * @Date: 2024/7/31 11:35
 * @LastModified: 2024-07-31 11:35
 * @LastModifiedBy: liuer
 */
// 判断
import 'package:common_utils/common_utils.dart';

extension StringJudgment on String {
  // 空判断
  bool get fxIsEmpty {
    return this == null || length == 0 || this == '' || this == 'null';
  }
  // 非空判断
  bool get fxIsNotEmpty {
    return this != null && length != 0 && this != '' && this != 'null';
  }
  // 转小数
  double? get fxToDouble {
    return double.tryParse(this);
  }
  // 转正数
  int? get fxToInt {
    return int.tryParse(this);
  }
  static String hideMiddleFourDigits(String phoneNumber) {
    // 正则表达式匹配手机号码中间四位
    final RegExp regex = RegExp(r'(\d{3})\d{4}(\d{4})');
    // 用 "****" 替换中间四位
    return phoneNumber.replaceAllMapped(regex, (Match match) => '${match[1]}****${match[2]}');
  }
}

// 列表判断
extension ListJudgment on List {
  // 空判断
  bool get fxIsEmpty {
    return this == null || length == 0;
  }
  // 非空判断
  bool get fxIsNotEmpty {
    return this != null && length > 0;
  }
  // 去重
  List<String> get fxFilterRepeat {
    List<String> result = [];
    for (var value in this) {
      var str = value is String ? value : value.toString();
      if (!result.contains(str)) {
        result.add(str);
      }
    }
    return result;
  }
}

// 判断
extension MapJudgment on Map {
  // 空判断
  bool get fxIsEmpty {
    return this == null || length == 0;
  }
  // 非空判断
  bool get fxIsNotEmpty {
    return this != null && length > 0;
  }
}


